package net.csdn.business.webhook.mapper;

import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.csdn.business.webhook.entity.WebhookConfig;
import net.csdn.business.common.domain.query.WebhookConfigQuery;
import net.csdn.business.common.domain.vo.WebhookConfigVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @ClassName WebhookConfigMapper
 * @Description webhook配置信息的Mapper接口
 * @Author zhangyl
 * @Date 2023/4/23 16:33
 */
public interface WebhookConfigMapper extends BaseMapper<WebhookConfig>
{

    /**
     * 分页查询webhook配置信息列表
     *
     * @param query 字典类型信息
     * @return 字典类型集合信息
     */
    @Select("<script> " +
            "select t1.object_id,t1.from_id,t1.notify_url,t1.encrypt_url_iv,t1.is_active,t1.req_body_type,t1.created_date FROM webhook_config t1 " +
            "where t1.from_id=#{query.fromId} " +
            "<if test=\"query.type != null\"> " +
            "         and t1.type = #{query.type} " +
            "</if> " +
            "order by t1.created_date desc " +
            "</script> ")
    public List<WebhookConfigVO> findPageList(Page page, @Param("query") WebhookConfigQuery query);

    /**
     * 查询webhook配置信息
     * 
     * @param id webhook配置信息主键
     * @return webhook配置信息
     */
    @Select("select t1.* FROM webhook_config t1 where t1.object_id=#{id}")
    public WebhookConfigVO selectWebhookConfigById(String id);

    /**
     * 查询webhook配置信息列表
     * 
     * @param fromId webhook配置主体信息
     * @return webhook配置信息集合
     */
    @Select("select t1.* FROM webhook_config t1 where t1.from_id=#{fromId} order by t1.created_date asc")
    public List<WebhookConfigVO> selectWebhookConfigList(@Param("fromId") String fromId);


    /**
     * 根据webhook配置id删除webhook配置信息
     * 
     * @param id webhook配置信息主键
     * @return 结果
     */
    @Delete("DELETE FROM webhook_config where object_id=#{id}")
    public Integer deleteWebhookConfigById(@Param("id")String  id);

}
